/*
2021-8-11
https://www.acwing.com/problem/content/1089/
*/ 
#include<iostream>
#include<cstring>
#include<algorithm>

using namespace std;
typedef long long ll;
const int N=1e5+5;
ll f[N],s[N];
int q[N];

ll get(int x)
{
    return f[x-1]-s[x];
}

int main()
{
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
        cin>>s[i];
        s[i]+=s[i-1];
    }
    
    int hh=0,tt=0;
    
    for(int i=1;i<=n;i++)
    {
        if(q[hh]+k<i) hh++;
        f[i]=max(f[i-1],get(q[hh])+s[i]);
        while(hh<=tt && get(i)>=get(q[tt])) tt--;
        q[++tt]=i;
    }
    
    cout<<f[n]<<endl;
    
    return 0;
}
